import { IPSAppCounter } from './ipsapp-counter';
import { IPSAppCounterRef } from './ipsapp-counter-ref';
import { PSSysCounterRefImpl } from '../../control/counter/pssys-counter-ref-impl';

export class PSAppCounterRefImpl extends PSSysCounterRefImpl implements IPSAppCounterRef {
  protected psappcounter: IPSAppCounter | null = null;

  getPSAppCounter(): IPSAppCounter | null {
    if (this.psappcounter != null) return this.psappcounter;
    const value = this.M.getPSAppCounter;
    if (value == null) {
      return null;
    }
    this.psappcounter = this.getPSModel4('app.control.IPSAppCounter', value, 'getPSAppCounter') as IPSAppCounter;
    return this.psappcounter;
  }

  get psAppCounter(): IPSAppCounter | null {
    return this.getPSAppCounter();
  }

  getPSAppCounterMust(): IPSAppCounter {
    const value = this.getPSAppCounter();
    if (value == null) {
      throw new Error('未指定应用计数器');
    }
    return value;
  }

  get cls(): string {
    return 'PSAppCounterRefImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'app.control.IPSAppCounterRef') return true;
    return super.instanceof(cls);
  }
}
